package 后台线程;

public class text {
    public static void main(String[] args) {
        //判断是否为后台线程
        System.out.println("main线程是后台线程吗" + Thread.currentThread().isDaemon());
        DaemonThread daemonThread = new DaemonThread();
        Thread thread = new Thread(daemonThread, "后台线程");
        thread.setDaemon(true);
        thread.start();
        //在主方法中执行其他任务
        for (int i = 0; i < 5; i++) {
            System.out.println(i);
        }

    }
}
    class DaemonThread extends Thread{

        public void run() {
        while (true) {


        System.out.println(Thread.currentThread().getName()+"---正在运行");}
        }
    }

